package zuoye729;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SortDemo {
	public static void main(String[] args) throws Exception {
		BufferedReader read1=new BufferedReader(new FileReader("sort.txt"));
		ArrayList<String> list=new ArrayList<>();
		String line=null;
	
		while((line=read1.readLine())!=null){
			//System.out.println(line);
			list.add(line);	
			
		}
	    read1.close();	
	    System.out.println(list);
		
	   List<String> collect = list.stream().sorted().collect(Collectors.toList());
  	   System.out.println(collect);
	   BufferedWriter out=new BufferedWriter(new FileWriter("sort.txt"));
		for(String s:collect){
			out.write(s);
			out.newLine();
			
		}    
		out.close();
		
		
		
		
		
		
		
	}

}
